-- ImageDemo.lua
-- Author: Mikael Kindborg
-- Date: 2011-02-22
-- Description: Demo that shows how to download and 
-- display images in Lua.

Images = {}

function DrawImages()
  maSetColorRGB(0, 0, 0)
  maFillRect(0, 0, Screen.getWidth(), Screen.getHeight())
  local y = 0
  for i,image in ipairs(Images) do
    maDrawImage(image, 0, y)
    y = y + EXTENT_Y(maGetImageSize(image))
  end
  maUpdateScreen()
end

function AddImage(image)
  if nil ~= image then
    table.insert(Images, image)
    DrawImages()
  end
end

System.downloadImage(
  "http://www.mosync.com/files/press/images/dusyant_thumb.png",
  AddImage)
  
System.downloadImage(
  "http://www.mosync.com/files/press/images/henrik_thumb.jpg",
  AddImage)
  
System.downloadImage(
  "http://www.mosync.com/files/press/images/alex_thumb.jpg",
  AddImage)
